package model

import (
	"database/sql"
)

type AuthRuleRetData struct {
	Id        string     `json:"id" db:"id"`
	Name      string     `json:"name" db:"name"`
	ChildAuth []AuthRule `json:"child_auth" db:"child_auth"`
}

type AuthRule struct {
	Id   string `json:"id" db:"id"`
	Name string `json:"name" db:"name"`
	Pid  int32  `json:"pid" db:"pid"`
}

// 获取总后台玩家 菜单列表
func GetAdminMenu(id string) []AuthRuleRetData {
	data := []AuthRuleRetData{}
	admin, _ := GetAdminInfoById(id)
	permisson, _ := GetPermissionById(admin.GroupID)
	query := "select id,name from tbl_admin_priv where state=1 and pid=0 and id in(" + permisson.Permission + ") order by sortlevel asc"

	err := meta.MerchantDB.Select(&data, query)

	if err != nil && err != sql.ErrNoRows {
		return data
	}
	for key, value := range data {
		query := "select id,name,pid from tbl_admin_priv where state=1 and pid=" + value.Id + " order by sortlevel asc"
		_ = meta.MerchantDB.Select(&data[key].ChildAuth, query)
	}
	return data
}
